home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7527 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  127 lines

  1. Path: cliffy.lfwc.lockheed.com!news
  2. From: James Bassett <bassett@flash.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Solved memory leak BUT new question!!!
  5. Date: 23 Feb 1996 19:55:37 GMT
  6. Organization: Computer Science Corp.
  7. Message-ID: <4gl63p$fpb@cliffy.lfwc.lockheed.com>
  8. NNTP-Posting-Host: 11200855.-pcimport.lfwc.lockheed.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
  13.  
  14. Here is the original problem:
  15.  
  16. I am using Visual C++ 1.51 under Windows 3.1. Using an ODBC recordset and
  17. creating an instance of the set using the _new_ operator and then
  18. deleting the object with the _delete_ operator. But we lose the same
  19. amount of memory each time. Anyone know how to recover the lost memory or
  20. what are we doing wrong?
  21.  
  22. Below is an example:
  23.  
  24. /////////////////////////////////////////////////////////////////////////
  25. ////
  26. // CPlotDefset recordset
  27.  
  28. class CPlotDefset : public CRecordset
  29. {
  30.  
  31. public:
  32.         CPlotDefset(CDatabase* pDatabase = NULL);
  33.         
  34.  
  35. In another .h file a pointer is declared:
  36.  
  37. //
  38. //
  39.         CPlotDefset     *plotdef_set;   //Plot defintion set
  40.  
  41.  
  42. Then in a dialog box routine the following is done:
  43.  
  44. //
  45. //
  46.         plotdef_set = new CPlotDefset;   //Get an instance of plot
  47. definition set
  48.  
  49.         plotdef_set->Open();                    //Open the database set
  50.         
  51. //
  52.         
  53.         CPlotEx dlg;    //Dialog for existing plots
  54.         
  55.         if(dlg.DoModal() == IDOK)
  56.         {
  57.                 plotdef_set->Close();
  58.                 delete plotdef_set;             //delete the plot
  59. defintion set
  60.                 
  61.                 Invalidate();
  62.         }
  63. }
  64.                            
  65. After doing the delete plotdef_set not all of the memory is released.
  66.  
  67.                                 I hope someone can help!!
  68.  
  69.                                 Jim Bassett
  70.                                 bassett@flash.net
  71.  
  72.  
  73.  
  74. Later I change the parameter plotdef_set from bring a pointer to just an 
  75. object. This made the memory leak go away!! Question... WHY????
  76.  
  77. Below is the rewritten code:
  78.  
  79.  
  80. /////////////////////////////////////////////////////////////////////////
  81. ////
  82. // CPlotDefset recordset
  83.  
  84. class CPlotDefset : public CRecordset
  85. {
  86.  
  87. public:
  88.         CPlotDefset(CDatabase* pDatabase = NULL);
  89.         
  90.  
  91. In another .h file a pointer is declared:
  92.  
  93. //
  94. //
  95.         CPlotDefset     *plotdef_set;   //Plot defintion set
  96.  
  97.  
  98. Then in a dialog box routine the following is done:
  99.  
  100. //
  101. //
  102.  
  103.         plotdef_set.Open();                    //Open the database set
  104.         
  105. //
  106.         
  107.         CPlotEx dlg;    //Dialog for existing plots
  108.         
  109.         if(dlg.DoModal() == IDOK)
  110.         {
  111.                 plotdef_set.Close();
  112.  
  113.                 
  114.                 Invalidate();
  115.         }
  116. }
  117.  
  118.  
  119. I would think this should not correct this!
  120.  
  121.  
  122.  
  123.             I hope someone can answer this one!!
  124.  
  125.                 Jim Bassett
  126.  
  127.